<template>

  <div class="app-container">

    <el-row :gutter="20">
      <!-- 左侧公司数据 -->

      <el-col :span="4">
        <div class="head-container">
          <el-collapse v-model="isCollapsed" @change="handleCollapseChange">
            <el-collapse-item title="公司数据" name="1">
              <el-tree
                :data="companyOptions"
                :props="defaultProps"
                :expand-on-click-node="false"
                :filter-node-method="filterNode"
                ref="tree"
                node-key="id"
                default-expand-all
                highlight-current
                @node-click="handleNodeClick"
              />
            </el-collapse-item>
          </el-collapse>
        </div>
      </el-col>
      <!-- 右侧资产数据 -->
      <el-col :span="20">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="单位名称" prop="dname">
            <el-input
              v-model="queryParams.dname"
              placeholder="请输入单位名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="资产状态" prop="zstatus">
            <el-select v-model="queryParams.zstatus" placeholder="请选择资产状态" clearable>
              <el-option
                v-for="dict in dict.type.zc_status"
                :key="dict.label"
                :label="dict.label"
                :value="dict.label"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:user:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['system:user:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:user:remove']">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport" v-hasPermi="['system:user:import']">导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:user:export']">导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="zctzList" @selection-change="handleSelectionChange" width="55" align="center">
          <el-table-column label="唯一标识" align="center" prop="id" />
          <el-table-column label="资产编号" align="center" prop="zode" />
          <el-table-column label="申请单位" align="center" prop="sqname" />
          <el-table-column label="单位名称" align="center" prop="dname" />
          <el-table-column label="使用单位" align="center" prop="sname" />
          <el-table-column label="管理部门" align="center" prop="department" />
          <el-table-column label="负责人" align="center" prop="zpeople" />
          <el-table-column label="设备名称" align="center" prop="ename" />
          <el-table-column label="规格型号" align="center" prop="modles" />
          <el-table-column label="所在地点" align="center" prop="address" />
          <el-table-column label="入账日期" align="center" prop="enddate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.enddate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单价入账原值" align="center" prop="ori" />
          <el-table-column label="生产厂家" align="center" prop="manfunturer" />
          <el-table-column label="是否有合同" align="center" prop="contract" />
          <el-table-column label="资产状态" align="center" prop="zstatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.zc_status" :value="scope.row.zstatus"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['zctz:zctz:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['zctz:zctz:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改资产台账对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="资产编号" prop="zode">
          <el-input v-model="form.zode" placeholder="请输入资产编号" />
        </el-form-item>
        <el-form-item label="验收编号" prop="ycode">
          <el-input v-model="form.ycode" placeholder="请输入验收编号" />
        </el-form-item>
        <el-form-item label="申请单位" prop="sqname">
          <el-input v-model="form.sqname" placeholder="请输入申请单位" />
        </el-form-item>
        <el-form-item label="发起人" prop="person">
          <el-input v-model="form.person" placeholder="请输入发起人" />
        </el-form-item>
        <el-form-item label="事项标题" prop="title">
          <el-input v-model="form.title" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="单位名称" prop="dname">
          <el-input v-model="form.dname" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="建账单位" prop="jname">
          <el-input v-model="form.jname" placeholder="请输入建账单位" />
        </el-form-item>
        <el-form-item label="使用单位" prop="sname">
          <el-input v-model="form.sname" placeholder="请输入使用单位" />
        </el-form-item>
        <el-form-item label="管理部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入管理部门" />
        </el-form-item>
        <el-form-item label="负责人" prop="zpeople">
          <el-input v-model="form.zpeople" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="需报销人" prop="baoxiao">
          <el-input v-model="form.baoxiao" placeholder="请输入需报销人" />
        </el-form-item>
        <el-form-item label="设备名称" prop="ename">
          <el-input v-model="form.ename" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="规格型号" prop="modles">
          <el-input v-model="form.modles" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="资产来源" prop="pmethod">
          <el-input v-model="form.pmethod" placeholder="请输入资产来源" />
        </el-form-item>
        <el-form-item label="所在地点" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="设备技术情况" prop="ecir">
          <el-input v-model="form.ecir" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="月折旧率" prop="mRate">
          <el-input v-model="form.mRate" placeholder="请输入月折旧率" />
        </el-form-item>
        <el-form-item label="年折旧率" prop="yRate">
          <el-input v-model="form.yRate" placeholder="请输入年折旧率" />
        </el-form-item>
        <el-form-item label="残值率" prop="res">
          <el-input v-model="form.res" placeholder="请输入残值率" />
        </el-form-item>
        <el-form-item label="折旧年限" prop="deprec">
          <el-input v-model="form.deprec" placeholder="请输入折旧年限" />
        </el-form-item>
        <el-form-item label="已折旧期数" prop="depre">
          <el-input v-model="form.depre" placeholder="请输入已折旧期数" />
        </el-form-item>
        <el-form-item label="剩余折旧期数" prop="rest">
          <el-input v-model="form.rest" placeholder="请输入剩余折旧期数" />
        </el-form-item>
        <el-form-item label="残值" prop="scrap">
          <el-input v-model="form.scrap" placeholder="请输入残值" />
        </el-form-item>
        <el-form-item label="计量单位" prop="per">
          <el-input v-model="form.per" placeholder="请输入计量单位" />
        </el-form-item>
        <el-form-item label="税率" prop="rate">
          <el-input v-model="form.rate" placeholder="请输入税率" />
        </el-form-item>
        <el-form-item label="出厂日期" prop="birdate">
          <el-date-picker clearable
            v-model="form.birdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出厂日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入账日期" prop="enddate">
          <el-date-picker clearable
            v-model="form.enddate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入账日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数量" prop="num">
          <el-input v-model="form.num" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="form.price" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="单价入账原值" prop="ori">
          <el-input v-model="form.ori" placeholder="请输入单价入账原值" />
        </el-form-item>
        <el-form-item label="总入帐原值" prop="total">
          <el-input v-model="form.total" placeholder="请输入总入帐原值" />
        </el-form-item>
        <el-form-item label="已提折旧" prop="hbprov">
          <el-input v-model="form.hbprov" placeholder="请输入已提折旧" />
        </el-form-item>
        <el-form-item label="生产厂家" prop="manfunturer">
          <el-input v-model="form.manfunturer" placeholder="请输入生产厂家" />
        </el-form-item>
        <el-form-item label="供货单位" prop="supply">
          <el-input v-model="form.supply" placeholder="请输入供货单位" />
        </el-form-item>
        <el-form-item label="是否有合同" prop="contract">
          <el-input v-model="form.contract" placeholder="请输入是否有合同" />
        </el-form-item>
        <el-form-item label="合同编号" prop="concode">
          <el-input v-model="form.concode" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="合同金额" prop="money">
          <el-input v-model="form.money" placeholder="请输入合同金额" />
        </el-form-item>
        <el-form-item label="合同" prop="confile">
          <file-upload v-model="form.confile"/>
        </el-form-item>
        <el-form-item label="合同签订日期" prop="condate">
          <el-input v-model="form.condate" placeholder="请输入合同签订日期" />
        </el-form-item>
        <el-form-item label="资产状态" prop="zstatus">
          <el-select v-model="form.zstatus" placeholder="请选择资产状态">
            <el-option
              v-for="dict in dict.type.zc_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { listZctz,listZctzbyid, getZctz, delZctz, addZctz, updateZctz, deptCompanySelect } from '@/api/zctz/zctz'
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
import company from '@/views/system/company/index.vue'
import { deptTreeSelect } from '@/api/system/user'

export default {
  name: "Zctz",
  computed: {
    company() {
      return company
    }
  },
  dicts: ['zc_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产台账表格数据
      zctzList: [],
      // 公司数据
      companyOptions:undefined,


      defaultProps: {
        children: "children",
        label: "label"
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zode: null,
        ycode: null,
        sqname: null,
        person: null,
        title: null,
        dname: null,
        jname: null,
        sname: null,
        department: null,
        zpeople: null,
        baoxiao: null,
        ename: null,
        modles: null,
        zcode: null,
        pmethod: null,
        address: null,
        ecir: null,
        mRate: null,
        yRate: null,
        res: null,
        deprec: null,
        depre: null,
        rest: null,
        scrap: null,
        per: null,
        rate: null,
        birdate: null,
        enddate: null,
        num: null,
        price: null,
        ori: null,
        total: null,
        hbprov: null,
        manfunturer: null,
        supply: null,
        contract: null,
        constatus: null,
        concode: null,
        money: null,
        confile: null,
        condate: null,
        zstatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDeptTree();
  },
  methods: {
    /** 查询资产台账列表 */
    getList() {
      this.loading = true;
      listZctz(this.queryParams).then(response => {
        this.zctzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getzCList() {
      this.loading = true;
      listZctz(this.queryParams).then(response => {
        this.zctzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        zode: null,
        ycode: null,
        sqname: null,
        person: null,
        title: null,
        dname: null,
        jname: null,
        sname: null,
        department: null,
        zpeople: null,
        baoxiao: null,
        ename: null,
        modles: null,
        zcode: null,
        pmethod: null,
        address: null,
        ecir: null,
        mRate: null,
        yRate: null,
        res: null,
        deprec: null,
        depre: null,
        rest: null,
        scrap: null,
        per: null,
        rate: null,
        birdate: null,
        enddate: null,
        num: null,
        price: null,
        ori: null,
        total: null,
        hbprov: null,
        manfunturer: null,
        supply: null,
        contract: null,
        constatus: null,
        concode: null,
        money: null,
        confile: null,
        condate: null,
        zstatus: null
      };
      this.resetForm("form");
    },
    //查询公司下拉树结构
    getDeptTree() {
      deptCompanySelect().then(response => {
        this.companyOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.jname = data.label;
      this.getzCList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      alert(this.queryParams.zstatus)
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资产台账";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getZctz(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改资产台账";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateZctz(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZctz(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除资产台账编号为"' + ids + '"的数据项？').then(function() {
        return delZctz(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zctz/zctz/export', {
        ...this.queryParams
      }, `zctz_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>


